from flask import Blueprint,request
from moble import db,UserModel
user_bp=Blueprint("user_bp",__name__,url_prefix='/user')

@user_bp.route("/user",methods=['post'])
def user_creat():
    name=request.form.get("name")
    age = request.form.get("age")
    email = request.form.get("email")
    lst=UserModel(name=name,age=age,email=email)
    db.session.add(lst)
    db.session.commit()
    return "添加成功"
@user_bp.route('/yy',methods=["GET"])
def classmate():
    age = int(request.args.get("age"))
    #小于
    user_age1 = UserModel.query.filter(UserModel.age.__gt__(age)).all()
    #大于
    user_age2 = UserModel.query.filter(UserModel.age.__gt__(age)).all()
    return f"小于{age}岁的有：{user_age1},大于{age}岁的有：{user_age2}"

@user_bp.route('/ii',methods=["GET"])
def classmate_name():
    name = request.args.get('name')
    ret = UserModel.query.filter_by(name=name).first()
    user_lst = {
        '名字':ret.name,
        '年龄':ret.age,
        '宿舍号':ret.email
    }
    return f"名字是{name}的学生：{user_lst}"

@user_bp.route('/oo',methods=["GET"])
def classmate_num():
    email = request.args.get('email')
    ret = UserModel.query.filter_by(email=email).all()
    return f"宿舍号是{email}的是：{ret}"


